﻿$filePath = "D:\Docs\数据同步\对接表数据汇总_ordered.txt";
$content = Get-Content $filePath;
$lst = $content;
#$lst | Sort-Object {$_.Split()[1]} >> f:\test.txt

#测量行数
#Get-Content "f:\test.txt" | %{$_.Split()[0]}  | measure -Sum

#format output
$format = "insert into hvr_action (CHN_NAME, GRP_NAME, TBL_NAME, ACT_NAME, ACT_PARAMETERS) values ('yy', 'TGT', '{0}', 'Restrict', '/RefreshCondition=`"{{{1}}} like ''510010%''`"');";

$output = "";
foreach ($line in $lst)
{
   $items = $line.Split("	",[StringSplitOptions]::RemoveEmptyEntries);
   if ($items.Length -lt 3)
   {
   Write-Host $items
       #continute;
       continue;
   }
   $flag = $items[0];
    $tableName = $items[1].ToLower();
   $fieldNames = $items[2].Split(",",[StringSplitOptions]::RemoveEmptyEntries);

    $fieldName = $fieldNames[0].ToLower();
    $str =  $format -f $tableName,$fieldName;
    $output +=  $str +[System.Environment]::NewLine;
}

$output >> "f:/ttt_target.txt"
	#dir | ForEach-Object { "{0,-20} = {1,10} Bytes" -f $_.name, $_.Length } >> "f:ttt.txt"